using System;
using System.Collections.Generic;
using UnityEngine;

namespace EntityKit.Runtime
{
    /// <summary>
    /// 音频工具类，提供全局访问点
    /// </summary>
    public static partial class AudioKit
    {
        private static bool isInitialized = false;

        private static Transform root = null;

        public static bool Mute
        {
            get => BackgroundMute && SingleMute && WorldMute && AmbientMute && OneShootMute && MultipleMute;
            set
            {
                BackgroundMute = value;
                SingleMute = value;
                WorldMute = value;
                AmbientMute = value;
                OneShootMute = value;
                MultipleMute = value;
            }
        }

        /// <summary>
        /// 初始化音频系统
        /// </summary>
        public static void Initialize()
        {
            if (isInitialized) return;
            root = new GameObject("AudioKit").transform;
            BackgroundMusicInitialize();
            SingleSoundInitialize();
            OneShootSoundInitialize();
            MultipleSoundInitialize();
            WorldSoundInitialize();
            AmbientSoundInitialize();

            isInitialized = true;
        }

        /// <summary>
        /// 更新音频系统（每帧调用）
        /// </summary>
        public static void Update()
        {
            if (!isInitialized) return;
            BackgroundMusicUpdate();
            SingleSoundUpdate();
            OneShootSoundUpdate();
            MultipleSoundUpdate();
            WorldSoundUpdate();
            AmbientSoundUpdate();
        }

        /// <summary>
        /// 释放音频系统资源
        /// </summary>
        public static void Release()
        {
            if (!isInitialized) return;

            BackgroundMusicRelease();
            SingleSoundRelease();
            MultipleSoundRelease();
            WorldSoundRelease();
            OneShootSoundRelease();
            AmbientSoundRelease();
            isInitialized = false;
        }
    }
}